@extends('layouts.master')
@section('title')
    列表
@endsection
@push('stylesheets')
    <link href="{{ URL::asset('/static/web/css/plugins/sweetalert/sweetalert.css')}}?v=33" rel="stylesheet">
@endpush
@section('content')
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    @include('common.toolbar', ['pager' => $list])
                    <form class="layui-form form-horizontal" id="ajaxform">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>昵称</th>
                                <th>真实姓名</th>
                                <th>证件信息</th>
                                <th>身份</th>
                                <th>镖头</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($list as $index => $item)
                                <tr>
                                    <th>{{$item->id}}</th>
                                    <th>
                                        id:{{$item->user->id}}<br/>
                                        {{$item->user->nickname}}
                                    </th>
                                    <th>{{$item->realname}}<br/>{{$item->phone}}</th>
                                    <td> <a style= 'color:#0072bc; text-decoration : underline' onclick="show_license({{$index}})" >点击查看</a>
                                        <ul id="{{'license'.$index}}" style="display: none">
                                            <li><img src="{{$item->material['cartImgPros']}}" alt="身份证正面"></li>
                                            <li><img src="{{$item->material['cartImgCons']}}" alt="身份证反面"></li>
                                        </ul>
                                    </td>
                                    <th>
                                        {{$item->role_text}}
                                    </th>
                                    <th>
                                        @if($item->leader)
                                            昵称：{{$item->leaderInfo->nickname}}<br>
                                            手机号：{{$item->leaderInfo->mobile}}
                                        @else
                                            无
                                        @endif

                                    </th>
                                    <th>
                                        {{$item->status_text}}
                                    </th>
                                    <th>
                                        <div class="dropdown btn btn-info" >
                                            <div data-toggle="dropdown" class="dropdown-toggle" href="#">
                                                操作
                                            </div>
                                            <ul class="dropdown-menu animated fadeInRight m-t-xs">
                                                <li>
                                                    @if($item->status == 0)
                                                        <a class="btn btn-outline btn-success ajax-confirm" data-url="{{route('escort.change',['id'=>$item->id, 'status' => 1])}}" data-title="确定吗？" href="javascript:;">审核通过</a>
                                                        <a class="btn btn-outline btn-success" data-id="{{$item->id}}" onclick="reject(this)" data-title="确定吗？" href="javascript:;">驳回</a>
                                                    @elseif($item->status == 1)
                                                        <a class="btn btn-outline btn-success ajax-confirm" data-url="{{route('escort.change',['id'=>$item->id, 'status' => 2])}}" data-title="确定吗？" href="javascript:;">休息</a>
                                                    @elseif($item->status == 2)
                                                        <a class="btn btn-outline btn-success ajax-confirm" data-url="{{route('escort.change',['id'=>$item->id, 'status' => 1])}}" data-title="确定吗？" href="javascript:;">开工</a>
                                                    @endif
                                                    <a class="btn btn-outline btn-success load_iframe" href="javascript:;"
                                                       data-url="{{route('school.search', ['callback' => 'setSchool','escort_id'=>$item->id])}}"
                                                       data-width="800px" data-height="600px">选择学校</a>

                                                    {{--                                                    @if($item->role == 1)--}}
                                                    {{--                                                        <a class="btn btn-outline btn-success load_iframe" href="javascript:;"--}}
                                                    {{--                                                           data-url="{{route('user.search', ['callback' => 'setLeader', 'escort_id' => $item->id,'is_leader' => 1])}}" data-width="800px" data-height="600px">设置镖头</a>--}}
                                                    {{--                                                        <a class="btn btn-outline btn-success ajax-confirm" data-method="post" data-url="{{route('escort.be_leader',['id'=>$item->id])}}" data-title="确定吗？" href="javascript:;">成为镖头</a>--}}
                                                    {{--                                                    @elseif($item->role == 2)--}}
                                                    {{--                                                        <a class="btn btn-outline btn-success ajax-confirm" data-method="post" data-url="{{route('escort.cancel_leader',['id'=>$item->id])}}" data-title="确定吗？" href="javascript:;">取消镖头</a>--}}
                                                    {{--                                                    @endif--}}
                                                    {{--                                                        <a class="btn btn-danger ajax-confirm delete"--}}
                                                    {{--                                                       data-url="{{route('escort.destroy',['id'=>$item->id])}}" data-title="确定要删除该记录吗？" href="javascript:;">删除</a>--}}
                                                </li>
                                            </ul>
                                        </div>
                                    </th>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </form>
                    @include('common.pagination', ['pager' => $list])
                </div>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script>
        layui.use(['laydate', 'element','form'], function () {
            var form = layui.form;

        });
        function show_license(index){
            var viewer = new Viewer(document.getElementById('license'+index),{
                hidden: function () {
                    viewer.destroy();
                },
            });
            viewer.show()
        }

        function setSchool(school_ids, escort_id) {
            $.ajax({
                url: '{{route('escort.set_escort_schools')}}',
                type: 'POST',
                data: {school_ids, escort_id},
                dataType: "json",
                success: function (result) {
                    layer.msg(result.message, {time: 2000, icon: 1});
                    var index = parent.layer.getFrameIndex(window.name);
                    setTimeout(function () {
                        parent.layer.close(index);
                        window.parent.location.reload();
                    }, 1000);
                }
            });
        }

        function setLeader(uid, escort_id) {
            $.ajax({
                url: '{{route('escort.set_leader')}}',
                type: 'POST',
                data: {uid, escort_id},
                dataType: "json",
                success: function (result) {
                    layer.msg(result.message, {time: 2000, icon: 1});
                    var index = parent.layer.getFrameIndex(window.name);
                    setTimeout(function () {
                        parent.layer.close(index);
                        window.parent.location.reload();
                    }, 1000);
                }
            });
        }

        function reject(e) {
            var id = $(e).data('id')
            require(["{{ URL::asset('/static/web/js/plugins/sweetalert/sweetalert.min.js')}}"], function (swal) {
                layui.use(['laydate', 'element'], function () {
                    swal({
                        title: '驳回',
                        input: 'textarea',
                        confirmButtonText: "提交",
                        cancelButtonText: "取消",
                        showCancelButton: true
                    }).then(function (result) {

                        var reason = result.value;
                        if (reason && result.dismiss != 'cancel') {
                            var index = layer.load(0);
                            $.ajax({
                                url: '{{route('escort.change')}}',
                                type: 'GET',
                                data: {id, reason, status:-1},
                                dataType: "json",
                                success: function (result) {
                                    layer.close(index);
                                    if (result.errno || result.errno == 0) {
                                        layer.msg(result.message, {time: 2000, icon: 6});
                                        window.location.reload();
                                    } else {
                                        layer.msg(result.message, {time: 2000, icon: 5});
                                    }
                                }
                            });
                        }
                    })
                });
            });
        }
    </script>
@endsection
